package GUILayer.TableModel;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import DataLayer.Model.Service;

@SuppressWarnings("serial")
public class ServiceTableModel extends AbstractTableModel
{
	private ArrayList<Service> li = new ArrayList<Service>();
	private String[] columnNames = { "ID", "Spil", "Model", "Malestandard",
			"Pris" };

	public ServiceTableModel()
	{
	}

	public void PopulateList(ArrayList<Service> list)
	{
		if (list != null)
		{
			this.li = list;
		}
	}

	@Override
	public String getColumnName(int columnIndex)
	{
		return columnNames[columnIndex];
	}

	@Override
	public int getRowCount()
	{
		return li.size();
	}

	@Override
	public int getColumnCount()
	{
		return 5;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		if (li.size() > rowIndex)
		{
			Service s = li.get(rowIndex);
			switch (columnIndex)
			{
			case 0:
				return s.getServiceId();
			case 1:
				return s.getSpil();
			case 2:
				return s.getModel();
			case 3:
				return s.getMalestandard();
			case 4:
				return s.getPris();
			}
		}
		return null;
	}

	@Override
	public Class<?> getColumnClass(int columnIndex)
	{
		switch (columnIndex)
		{
		case 0:
			return int.class;
		case 1:
			return String.class;
		case 2:
			return String.class;
		case 3:
			return String.class;
		case 4:
			return getValueAt(0, columnIndex).getClass();
		}
		return null;
	}
}